<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding:0;
            margin:0;
        }
        #app {
            width: 400px;
            height: 400px;
            border:1px solid green;
            margin:20px auto;
            font-size: 0;
        }
    </style>
</head>
<body>
<div id="app"></div>
</body>
<script>
    const app = document.querySelector("#app");
    init();
    function init(col=2){
        const xzIndex = getRandom(0,col*col-1);// 徐峥所在的下标
        app.innerHTML = null;
        for(let i=0;i<col*col;i++){
            const img = new Image();
            img.width=img.height=app.clientWidth/col;
            img.src = i===xzIndex?"./img/1.png":"./img/2.png";
            img.onclick = function(){
                if(i===xzIndex){
                    alert("选对了！")
                    init(col+1)
                }else{
                    alert("选错了")
                }
            }
            app.appendChild(img);
        }
    }

    function getRandom(min,max){
        return Math.floor(Math.random()*(max-min+1)+min);
    }
</script>
</html>